<?php

namespace App\Http\Controllers\lxSystem;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\AdCategory;
class AdController extends Controller
{
    function __construct()
    {
        view()->share([
            'categories'=> AdCategory::get_categories()
        ]);
    }

    function index(Request $request){
        $where=function($query) use ($request){
            if($request->has('category_id')){
                $query->where('category_id',$request->category_id);
            }
        };

        $ads = Ad::with('category')->where($where)->orderBy('created_at')->paginate(config('xSystem.page_size'));
        return view('lxSystem.ad.ads.index')->with('ads', $ads);
    }
}
